package com.tank.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tank.bean.msg.PmContent;
import com.tank.core.TankModel;
import com.tank.service.PmService;

@Controller
@Scope("prototype")
public class PmAction extends ActionSupport {
	
	@Resource(name="pmService")
	PmService service;
	
	TankModel tm;

	private PmContent pc;
	private Integer id;
	
	
	
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
	
	
	
	public String trackers() throws Exception {
		tm=service.trackers();
		return SUCCESS;
	}
	
	public String dialog() throws Exception {
		try{
			tm=service.dialog(id);
			//tm.printData();
		}catch(Exception e){
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String send() throws Exception {
		if(pc== null || pc.getReceiptor() == null ){
			return INPUT;
		}
		
		System.out.println("zhuyro:"+id);
		
		
		tm=service.send(pc);
		
		if(tm.isSuccess()){
			return "ok";
			//return SUCCESS;
		}else{
			System.out.println(tm.getMessage());
			return INPUT;
		}
		
		
	}
	
	public String send2() throws Exception {
		if(pc== null || pc.getReceiptor() == null ){
			return INPUT;
		}
		
		System.out.println("zhuyro:"+id);
		
		
		tm=service.send(pc);
		
		if(tm.isSuccess()){
			//return "ok";
			return SUCCESS;
		}else{
			System.out.println(tm.getMessage());
			return INPUT;
		}
		
		
	}
	
	
	public String removeContent() throws Exception {
		
		
		if(service.removeContent(pc.getDialog().getId(), pc.getId())){
			
		}
		
		
		return SUCCESS;
	}

	public String removeBatch() throws Exception {
		if(service.removeBatch(id)){
			
		}
		return SUCCESS;
	}


	
	
	/**
	 * setter && getter
	 */
	
	public TankModel getTm() {
		return tm;
	}



	public void setTm(TankModel tm) {
		this.tm = tm;
	}



	public PmContent getPc() {
		return pc;
	}



	public void setPc(PmContent pc) {
		this.pc = pc;
	}



	public Integer getId() {
		return id;
	}



	public void setId(Integer id) {
		this.id = id;
	}
	
}
